package study.cdc.canal.support.utils;

import cn.hutool.core.map.MapUtil;
import com.alibaba.otter.canal.protocol.CanalEntry;

import java.util.List;
import java.util.Map;

public class ColumnUtils {

    public static Map<String, Object> toMap(List<CanalEntry.Column> columnsLt) {
        Map<String, Object> data = MapUtil.newHashMap();
        columnsLt.forEach(c -> data.put(c.getName(), c.getValue()));
        return data;
    }

    public static <T> T toBean(List<CanalEntry.Column> columnsLt, Class<T> clazz) {
        Map<String, Object> data = toMap(columnsLt);
        String text = JsonUtils.toJson(data);
        return JsonUtils.fromJson(text, clazz);
    }
}
